#!/usr/bin/python

import wx,sys

EVTTYPE_EVT_MINE = wx.NewEventType()
EVT_MINE = wx.PyEventBinder(EVTTYPE_EVT_MINE, 1)

class MyEvent(wx.PyCommandEvent):
	def __init__(me, evtType, id):
		wx.PyCommandEvent.__init__(me, evtType, id)
	
	def do(me): 
		return 'foobar!'

class Child(wx.Button):
	def __init__(me,parent):
		wx.Button.__init__(me,parent,-1,'Click Me!')
		me.Bind(wx.EVT_LEFT_DOWN, me.OnLeftDown)

	def OnLeftDown(me, event):
		ev = MyEvent(EVTTYPE_EVT_MINE, me.GetId())
		me.GetEventHandler().ProcessEvent(ev)
		event.Skip()
		
class MainPanel(wx.Panel):

	def __init__(me,parent):
		wx.Panel.__init__(me,parent)
		me.child=Child(me)
		
		#me.Bind(EVT_MINE,lambda e: (e.Skip(), sys.stdout.write(str(me)+e.do()+'\n')))
		me.Bind(EVT_MINE,me.hd)
		
	def hd(me,e):
		print 'panel'
		#print dir(e)
		print e.GetId()
		print me.child.GetId()
		e.SetId(27)#me.GetId())
		e.Skip()
				
# me.eventbus.broadcast(me)
# me.eventbus.named_broadcast('File_Open',from=me)

#	md = me.doc.MD_line_mod_status
#	fm.EventBus.listen_for(md, me.on_line_mod_status_change, md.OPEN | md.SAVE)
#	fm.EVENTBUS.listen_for(me.doc.MD_scroll_info, me.on_scroll_info_change)
		
class MainFrame(wx.Frame):

	def __init__(me):
			
		wx.Frame.__init__(me,parent=None)
		me.pn=MainPanel(parent=me)
		#me.Bind(EVT_MINE,lambda e: sys.stdout.write(str(me)+e.do()+'\n'))
		me.Bind(EVT_MINE,me.hd)
		
	def hd(me,e):
		print 'frame'
		print e.GetId()
		

app = wx.PySimpleApp()frame = MainFrame()
frame.Show()
frame.Centre()app.MainLoop()